﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;

namespace Lot.WebClient
{
    public class FormPostData:NameValueCollection,IPostData
    {
        public MimeType ContentType { get; private set; }

        public FormPostData()
        {
            ContentType = MimeType.FormUrlEncoded;
        }

        public string GetDataString()
        {
            return ((NameValueCollection)this).ToQueryString();
        }
    }

    internal static partial class Extensions
    {
        public static String ToQueryString(this NameValueCollection parameters)
        {
            List<String> items = new List<String>();

            foreach (String name in parameters)
                items.Add(String.Concat(name, "=", System.Web.HttpUtility.UrlEncode(parameters[name])));

            return String.Join("&", items.ToArray());
        }

    }
}
